package com.yoomiito.app.widget.state;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.utils.ColorUtils;
import com.yoomiito.app.utils.DensityUtil;

public class ErrorType extends ContentType {
    private View.OnClickListener clickListener;
    private int marginTop;
    public ErrorType() {
        super(R.layout.layout_error);
    }

    public ErrorType( View.OnClickListener clickListener) {
        super(R.layout.layout_error);
        this.clickListener = clickListener;
    }

    @Override
    public void show(View rootView) {
        TextView retryTv = rootView.findViewById(R.id.retry);
        retryTv.setBackground(ColorUtils.INSTANCE.background(R.color.color_5CB331,23));
        retryTv.setOnClickListener(clickListener);
        TextView errorTv = rootView.findViewById(R.id.errorTv);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) errorTv.getLayoutParams();
        lp.topMargin = DensityUtil.dp2px(marginTop);
//        ImageView imageView = (ImageView) rootView.findViewById(R.id.errorImageView);
//        if (NetworkUtils.isNetworkConnected()) {
//            imageView.setImageResource(R.drawable.bg_loading_error);
//        } else {
//            imageView.setImageResource(R.drawable.bg_no_network);
//        }
//        if (clickListener != null) {
//            rootView.setOnClickListener(clickListener);
//        }
    }

    public ErrorType setClickListener(View.OnClickListener clickListener) {
        this.clickListener = clickListener;
        return this;
    }

    public ErrorType setMarginTop(int marginTop) {
        this.marginTop = marginTop;
        return this;
    }
}
